package org.jeecg.qis.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.qis.service.IQisProcdetailValueService;
import org.jeecg.qis.service.IQisProcheadValueService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.qis.entity.QisProcrecord;
import org.jeecg.qis.service.IQisProcrecordService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: qis_procrecord
 * @Author: licy
 * @Date: 2023-05-21
 * @Version: V1.0
 */
@Api(tags = "qis_procrecord")
@RestController
@RequestMapping("/qis/qisProcrecord")
@Slf4j
public class QisProcrecordController extends JeecgController<QisProcrecord, IQisProcrecordService> {
	@Autowired
	private IQisProcrecordService qisProcrecordService;
	@Autowired
	private IQisProcheadValueService iQisProcheadValueService;
	@Autowired
	private IQisProcdetailValueService iQisProcdetailValueService;

	/**
	 * 单表分页列表查询
	 *
	 * @param qisProcrecord
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "qis_procrecord-分页列表查询", notes = "qis_procrecord-分页列表查询")
	@GetMapping(value = "/list")
	@DS("history")
	public Result<IPage<QisProcrecord>> queryPageList(QisProcrecord qisProcrecord,
													  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
													  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
													  HttpServletRequest req) {
		QueryWrapper<QisProcrecord> queryWrapper = QueryGenerator.initQueryWrapper(qisProcrecord, req.getParameterMap());
		Page<QisProcrecord> page = new Page<QisProcrecord>(pageNo, pageSize);
		IPage<QisProcrecord> pageList = qisProcrecordService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 * 单表分页列表查询
	 *
	 * @param qisProcrecord
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "qis_procrecord-分页列表查询", notes = "qis_procrecord-分页列表查询")
	@GetMapping(value = "/opList")
	@DS("history")
	public Result<List<Map<String, String>>> queryOpList(QisProcrecord qisProcrecord,
														 @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
														 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
														 HttpServletRequest req) {
		List<Map<String, String>> queryOpList = iQisProcheadValueService.queryOpList(qisProcrecord);
		return Result.OK(queryOpList);
	}

	/**
	 * 单表分页列表查询
	 *
	 * @param param
	 * @return
	 */
	@ApiOperation(value = "qis_procrecord-分页列表查询", notes = "qis_procrecord-分页列表查询")
	@GetMapping(value = "/detailColumnList")
	@DS("history")
	public Result<List<Map<String, String>>> queryDetailColumnList(Map<String, String> param) {
		List<Map<String, String>> data = iQisProcdetailValueService.queryDetailColumnList(param);
		return Result.OK(data);
	}

	/**
	 * 单表分页列表查询
	 *
	 * @param param
	 * @return
	 */
	@ApiOperation(value = "qis_procrecord-分页列表查询", notes = "qis_procrecord-分页列表查询")
	@GetMapping(value = "/detailList")
	@DS("history")
	public Result<List<Map<String, Object>>> queryDetailList(Map<String, String> param) {
		List<Map<String, Object>> maps = iQisProcdetailValueService.queryDetailList(param);
		return Result.OK(maps);
	}

	/**
	 * 添加
	 *
	 * @param qisProcrecord
	 * @return
	 */
	@AutoLog(value = "qis_procrecord-添加")
	@ApiOperation(value = "qis_procrecord-添加", notes = "qis_procrecord-添加")
	@PostMapping(value = "/add")
	@DS("business")
	public Result<String> add(@RequestBody QisProcrecord qisProcrecord) {
		qisProcrecordService.save(qisProcrecord);
		return Result.OK("添加成功！");
	}



	/**
	 * 通过map删除
	 *
	 * @param map
	 * @return
	 */
	@AutoLog(value = "qis_procrecord-通过id删除")
	@ApiOperation(value = "qis_procrecord-通过id删除", notes = "qis_procrecord-通过id删除")
	@DeleteMapping(value = "/delete")
	@DS("business")
	public Result<String> delete(@RequestParam Map<String, Object> map) {
		HashMap<String, Object> hashMap = new HashMap<>();
		hashMap.put("", map.get(""));
		//自定义查询条件，下面的值全部满足才能删除成功
		qisProcrecordService.removeByMap(hashMap);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "qis_procrecord-批量删除")
	@ApiOperation(value = "qis_procrecord-批量删除", notes = "qis_procrecord-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	@DS("business")
	public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
		this.qisProcrecordService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "qis_procrecord-通过id查询")
	@ApiOperation(value = "qis_procrecord-通过id查询", notes = "qis_procrecord-通过id查询")
	@GetMapping(value = "/queryById")
	@DS("history")
	public Result<QisProcrecord> queryById(@RequestParam(name = "id", required = true) String id) {
		QisProcrecord qisProcrecord = qisProcrecordService.getById(id);
		if (qisProcrecord == null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(qisProcrecord);
	}

	/**
	 * 导出excel
	 *
	 * @param request
	 * @param qisProcrecord
	 */
	@RequestMapping(value = "/exportXls")
	@DS("history")
	public ModelAndView exportXls(HttpServletRequest request, QisProcrecord qisProcrecord) {
		return super.exportXls(request, qisProcrecord, QisProcrecord.class, "qis_procrecord");
	}

	/**
	 * 通过excel导入数据
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
	@DS("business")
	public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
		return super.importExcel(request, response, QisProcrecord.class);
	}

}
